var vue = new Vue({
    el: '#app',
    data() {
        return {
            mobile: '',
            code: '',
            bizCode: '',
            step1Visible: false,
            step2Visible: false,
            step3Visible:false,
            timeVisible:false,
            num: 60,
            confirmVisible:false,
			agreement: false, // 新增的变量
        }
    },
    mounted() {
        this.step1Visible = true;
    },
    methods: {
		handlePhone() {
          window.location.href = "tel:4000022056";
        },
		 showAgreement() {
            fetch('./file/read.txt') // 替换为您的文本文件的路径
                .then(response => response.text())
                .then(data => {
                    document.getElementById('agreementText').textContent = data;
                    document.getElementById('agreementModal').style.display = "block";
                })
                .catch(error => console.error('Error fetching the text file:', error));
        },
        closeModal() {
            document.getElementById('agreementModal').style.display = "none";
        },
        checkPhone:function() {
            console.log("clickPhone");
            var phone = this.mobile;
            if (phone.length == 11) {
                this.step1Visible = false;
                this.step2Visible = true;
            }
        },
        checkCode: function () {
            var code = this.code;
            if (code.length === 4) {
                this.step3Visible = false;
            }
        },
        getCode: function () {
            let _this=this;
            var phone = this.mobile;
            if (phone.length != 11) {
                this.step1Visible = true;
                return;
            }
            let settings = {
                "url": "https://ldwxmc.com/CrbtByProvice/hunan/sendSmsVerifyCodeOut",
                "method": "POST",
                "timeout": 0,
                "headers": {
                    "Content-Type": "application/json"
                },
                "data": JSON.stringify({
					discntCode: "99867941",
                    fee: "1990",
                    cpid: "test",
                    mobile: phone,
                    tradeTypeCode: "110",
                    appId: "710313"
                }),
            };
            this.timeVisible = true;
            var timer = setInterval(() => {
                this.num--;
                if (this.num == 0) {
                    clearInterval(timer);
                    this.timeVisible = false;
                    this.num = 60;
                }
            }, 1000);
            this.step2Visible = false;
            $.ajax(settings).done( (res)=> {
                console.log(res);
                if(res.state==='success'){
                    if (res.data.respCode==='0'){
                        this.step3Visible = true;
                    }else {
                        alert(res.data.respDesc);
                        _this.reset();
                    }



                }else {
                    alert(res.respDesc);
                    _this.reset();
                }
            });
        },

        reset: function () {
            this.mobile = '';
            this.code = '';
            this.step1Visible = true;
            this.step2Visible = false;
            this.timeVisible= false
        },

        checkCodeVal:function (){
			if(!this.agreement){
				alert('请您阅读并同意个人信息授权和保护声明');
				return;
			}
            var code = this.code;
            if (code.length !== 6) {
                alert('请输入正确的验证码');
                return;
            }
            this.confirmVisible = true;
        },

        closeConfirm: function () {
            this.confirmVisible = false;
        },

        submit: function () {
            var phone = this.mobile;
            var code = this.code;
            if (phone.length != 11) {
                alert('请输入正确的手机号码');
                return;
            }
            if (code.length != 6) {
                alert('请输入正确的验证码');
                return;
            }
            let setting={
                "url": "https://ldwxmc.com/CrbtByProvice/hunan/productChangeOut",
                "method": "POST",
                "timeout": 0,
                "headers": {
                    "User-Agent": "Apifox/1.0.0 (https://apifox.com)",
                    "Content-Type": "application/json"
                },
                "data": JSON.stringify({
                    mobile: phone,
                    discntCode: "99867941",
                    cpid: "test",
                    fee: "1990",
                    appId: "710313",
                    tradeTypeCode: "110",
                    verifyCode: code,
					productName:"视频彩铃-美播尊享版",
					keepType:"0",
                }),
            };
            $.ajax(setting).done( (res) =>{
                console.log(res);
                if(res.state==='error'){
                    alert(res.respDesc);
                }else if(res.data.respCode==='0'){
                    alert('请求已提交，订购结果以短信为准！');
                    this.closeConfirm();
                }else{
					alert(res.data.respDesc);
				}
            });
        }
    }
})
